/*
* INSANE - Interactive Structural Analysis Environment
*
* Copyright (C) 2003-2006
* Universidade Federal de Minas Gerais
* Escola de Engenharia
* Departamento de Engenharia de Estruturas
* 
* Author's email :    insane@dees.ufmg.br
* Author's website :  http://www.dees.ufmg.br/insane
* 
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or any later version.
* 
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
* 
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/
package br.ufmg.dees.insane.continuousPointModel;

import java.io.Serializable;

import br.ufmg.dees.insane.util.IMatrix;
import br.ufmg.dees.insane.util.IVector;

/** A class representing PlaneStressPoint
 * @author Jamile Fuina, Flavio
 * @since October, 2006
 */
public class PlaneStressPoint implements ContinuousPointModel, Serializable {
	
	private static final long serialVersionUID = 1L;

	/**Constructs a Plane Stress Analysis Model.*/
    public PlaneStressPoint()
	{
    	super();
	}
    
    /* (non-Javadoc)
     * @see br.ufmg.dees.insane.analysisModel.AnalysisModel#getLabel()
     */
    public String getLabel() {
        return "PlaneStressPoint";
    }

    /* (non-Javadoc)
     * @see br.ufmg.dees.insane.analysisModel.AnalysisModel#getDualInternalVariableOperator(br.ufmg.dees.insane.util.IMatrix)
     */
    public IMatrix getDualInternalVariableOperator(IMatrix e){
    	IMatrix d = new IMatrix(3,3);
		d.setZero();
		double elast = e.getElement(0,0);
		double ni = e.getElement(2,0);
		double k = ((elast)/(1-(ni*ni)));
		d.setElement(0,0,(1*k));
		d.setElement(0,1,(ni*k));
		d.setElement(0,2,0);
		d.setElement(1,0,(ni*k));
		d.setElement(1,1,(1*k));
		d.setElement(1,2,0);
		d.setElement(2,0,0);
		d.setElement(2,1,0);
		d.setElement(2,2,(((1-ni)/2)*k));
		return(d);
    }
    
//    /* (non-Javadoc)
//     * @see br.ufmg.dees.insane.analysisModel.AnalysisModel#modifyDualInternalVariableOperator(br.ufmg.dees.insane.util.IMatrix, java.util.ArrayList)
//     */
//	public IMatrix modifyDualInternalVariableOperator(IMatrix e, GeometricProperties gps)	{
//		return e;
//	}
    
    /* (non-Javadoc)
     * @see br.ufmg.dees.insane.analysisModel.AnalysisModel#getNumberOfInternalVariables()
     */
    public int getNumberOfInternalVariables(){
    	return 3;
    }

    /* (non-Javadoc)
     * @see br.ufmg.dees.insane.analysisModel.AnalysisModel#getNumberOfDualInternalVariables()
     */
    public int getNumberOfDualInternalVariables(){
    	return 3;
    }

//    /* (non-Javadoc)
//     * @see br.ufmg.dees.insane.analysisModel.AnalysisModel#getInternalVariablesVector(br.ufmg.dees.insane.util.IVector, br.ufmg.dees.insane.util.IMatrix)
//     */
//    public IVector getInternalVariablesVector(IVector a, IMatrix b){    	
//    	IVector strainVector = new IVector(4);
//		strainVector.setElement(0, a.getElement(0)); 
//		strainVector.setElement(1, a.getElement(1));
//		strainVector.setElement(2, (-b.getElement(2,0)/(1 - b.getElement(2,0)))*(a.getElement(0)+a.getElement(1)));
//		strainVector.setElement(3, a.getElement(2));
//		return strainVector;
//    }

//    /* (non-Javadoc)
//     * @see br.ufmg.dees.insane.analysisModel.AnalysisModel#getInternalDualVariablesVector(br.ufmg.dees.insane.util.IVector, br.ufmg.dees.insane.util.IMatrix)
//     */
//    public IVector getDualInternalVariablesVector(IVector a, IMatrix b){
//    	return a;
//    }
//
//    /* (non-Javadoc)
//     * @see br.ufmg.dees.insane.analysisModel.AnalysisModel#getInternalVariablesTensor(br.ufmg.dees.insane.util.IVector, br.ufmg.dees.insane.util.IMatrix)
//     */
//    public IMatrix getInternalVariablesTensor(IVector a, IMatrix b){
//        IMatrix Tensor = new IMatrix(3,3);
//        Tensor.setElement(0,0,a.getElement(0));
//        Tensor.setElement(0,1,a.getElement(2));
//        Tensor.setElement(1,1,a.getElement(1));
//        Tensor.setElement(1,0,a.getElement(2));
//        Tensor.setElement(2,2,-b.getElement(2,0)/(1 - b.getElement(2,0))*(a.getElement(0)+a.getElement(1)));
//        return Tensor;	
//    }
//
//    /* (non-Javadoc)
//     * @see br.ufmg.dees.insane.analysisModel.AnalysisModel#getInternalDualVariablesTensor(br.ufmg.dees.insane.util.IVector, br.ufmg.dees.insane.util.IMatrix)
//     */
//    public IMatrix getDualInternalVariablesTensor(IVector a, IMatrix b){
//    	return expandTensor(a); 
//    }

    /* (non-Javadoc)
     * @see br.ufmg.dees.insane.analysisModel.AnalysisModel#getInternalVariablesDirLabels()
     */
    public String[] getInternalVariablesLabels(){
    	 String[] Dlabels = {"xx", "yy", "xy"};
         return Dlabels;
    }

    /* (non-Javadoc)
     * @see br.ufmg.dees.insane.analysisModel.AnalysisModel#getInternalDualVariablesDirLabels()
     */
    public String[] getDualInternalVariablesLabels(){
    	String[] Dlabels = {"xx", "yy", "xy"};
        return Dlabels;
    }

    /* (non-Javadoc)
     * @see br.ufmg.dees.insane.analysisModel.AnalysisModel#expandVector(br.ufmg.dees.insane.util.IVector)
     */
    public IVector expandVector(IVector a){
    	IVector Vector = new IVector(6);
        Vector.setElement(0,a.getElement(0));
        Vector.setElement(1,a.getElement(1));
        Vector.setElement(3,a.getElement(2));
        return Vector;
    }

    /* (non-Javadoc)
     * @see br.ufmg.dees.insane.analysisModel.AnalysisModel#expandTensor(br.ufmg.dees.insane.util.IVector)
     */
    public IMatrix expandTensor(IVector a){
    	IMatrix Tensor = new IMatrix(3,3);
        Tensor.setElement(0,0,a.getElement(0));
        Tensor.setElement(0,1,a.getElement(2));
        Tensor.setElement(1,1,a.getElement(1));
        Tensor.setElement(1,0,a.getElement(2));
        return Tensor;
    }

    /* (non-Javadoc)
     * @see br.ufmg.dees.insane.analysisModel.AnalysisModel#reduceVector(br.ufmg.dees.insane.util.IVector)
     */
    public IVector reduceVector(IVector a){
    	IVector Vector = new IVector(3);
        Vector.setElement(0,a.getElement(0));
        Vector.setElement(1,a.getElement(1));
        Vector.setElement(2,a.getElement(3));
        return Vector;
    }
    
    /* (non-Javadoc)
     * @see br.ufmg.dees.insane.analysisModel.AnalysisModel#reduceTensor(br.ufmg.dees.insane.util.IMatrix)
     */
    public IVector reduceTensor(IMatrix a){
    	IVector Vector = new IVector(3);
        Vector.setElement(0,a.getElement(0,0));
        Vector.setElement(1,a.getElement(1,1));
        Vector.setElement(2,a.getElement(0,1));
        return Vector;
    }
//    
//    /* (non-Javadoc)
//     * @see br.ufmg.dees.insane.analysisModel.AnalysisModel#getDeviatoricDualInternalVariable(br.ufmg.dees.insane.util.IMatrix)
//     */
//    public IVector getDeviatoricDualInternalVariable(IVector s){
//    	IVector deviatoric = new IVector(4);
//    	double p = (s.getElement(0) + s.getElement(1))/3.0;
//    	deviatoric.setElement(0,s.getElement(0)- p);
//    	deviatoric.setElement(1,s.getElement(1)- p);
//    	deviatoric.setElement(2,-p);
//    	deviatoric.setElement(3,s.getElement(2));
//    	return deviatoric;
//    }
//    
//    /* (non-Javadoc)
//     * @see br.ufmg.dees.insane.analysisModel.AnalysisModel#getDeviatoricInternalVariable(br.ufmg.dees.insane.util.IMatrix)
//     */
//    public IVector getDeviatoricInternalVariable(IVector e){	
//    	IVector deviatoric = new IVector(4);
//    	double p = (e.getElement(0) + e.getElement(1) + e.getElement(2))/3.0;
//    	deviatoric.setElement(0,e.getElement(0)- p);
//    	deviatoric.setElement(1,e.getElement(1)- p);
//    	deviatoric.setElement(2,e.getElement(2)- p);
//    	deviatoric.setElement(3,e.getElement(3));
//    	return deviatoric;
//    }
//    
//    /* (non-Javadoc)
//     * @see br.ufmg.dees.insane.analysisModel.AnalysisModel#getJ2(br.ufmg.dees.insane.util.IMatrix)
//     */
//    public double getJ2(IVector s){
//    	IVector dev = this.getDeviatoricDualInternalVariable(s);
//        double J2  = (dev.getElement(0)* dev.getElement(0)+dev.getElement(1)* dev.getElement(1)+dev.getElement(2)* dev.getElement(2))/2.0 + dev.getElement(3)* dev.getElement(3);
//        return(J2);
//    }
//    
//    /* (non-Javadoc)
//     * @see br.ufmg.dees.insane.analysisModel.AnalysisModel#getdJ2dSIG(br.ufmg.dees.insane.util.IMatrix)
//     */
//    public IVector getdJ2dSIG (IVector s){
//    	IVector derivate = new IVector(3);
//        derivate.setElement(0,(2.0*s.getElement(0)-s.getElement(1))/3.0);
//        derivate.setElement(1,(2.0*s.getElement(1)-s.getElement(0))/3.0);
//        derivate.setElement(2,(2.0*s.getElement(2)));
//        return derivate;
//    }
//    
//    /* (non-Javadoc)
//     * @see br.ufmg.dees.insane.analysisModel.AnalysisModel#getJ3(br.ufmg.dees.insane.util.IMatrix)
//     */
//    public double getJ3(IVector s){
//    	IVector dev = this.getDeviatoricDualInternalVariable(s);
//        double J3  = dev.getElement(0)* dev.getElement(1)* dev.getElement(2) - dev.getElement(3)* dev.getElement(3)* dev.getElement(2);
//        return(J3);
//    }
//    
//    /* (non-Javadoc)
//     * @see br.ufmg.dees.insane.analysisModel.AnalysisModel#getdJ3dSIG(br.ufmg.dees.insane.util.IMatrix)
//     */
//    public IVector getdJ3dSIG (IVector s){
//    	IVector derivate = new IVector(3);
//    	double dJ3dsx = ((1.0/9.0) * (-2.0*s.getElement(0)*s.getElement(1)-s.getElement(1)*s.getElement(1)+2.0*s.getElement(0)*s.getElement(0)))+ ((1.0/3.0) * (s.getElement(2)*s.getElement(2)));
//    	double dJ3dsy = ((1.0/9.0) * (-2.0*s.getElement(0)*s.getElement(1)-s.getElement(0)*s.getElement(0)+2.0*s.getElement(1)*s.getElement(1)))+ ((1.0/3.0) * (s.getElement(2)*s.getElement(2)));
//    	double dJ3dsxy = ((2.0/3.0) * s.getElement(2) * (s.getElement(0)+s.getElement(1)));
//        derivate.setElement(0,dJ3dsx);
//        derivate.setElement(1,dJ3dsy);
//        derivate.setElement(2,dJ3dsxy);
//        return derivate;
//    }
//    
//    /* (non-Javadoc)
//     * @see br.ufmg.dees.insane.analysisModel.AnalysisModel#getI1(br.ufmg.dees.insane.util.IMatrix)
//     */
//    public double getI1(IVector s){
//    	return(s.getElement(0) + s.getElement(1));
//    }
//    
//    /* (non-Javadoc)
//     * @see br.ufmg.dees.insane.analysisModel.AnalysisModel#getdI1dSIG(br.ufmg.dees.insane.util.IMatrix)
//     */
//    public IVector getdI1dSIG (IVector s){
//    	IVector derivate = new IVector(2);
//        derivate.setElement(0,1.0);
//        derivate.setElement(1,1.0);
//        return derivate;
//    }
//    
//    /* (non-Javadoc)
//     * @see br.ufmg.dees.insane.analysisModel.AnalysisModel#getI2(br.ufmg.dees.insane.util.IMatrix)
//     */
//    public double getI2(IVector s){
//    	return(s.getElement(0) * s.getElement(1) - s.getElement(2) * s.getElement(2));
//    }
//    
	public IMatrix getInternalVariableOperator(IMatrix d, IMatrix d2, IVector n, IMatrix c) {
		IMatrix l = new IMatrix(3,3);
        l.setIdentity();
        return l;
	}

//	public IMatrix getInternalVariableOperator(IMatrix d, IMatrix d2, IVector n, IMatrix c, IMatrix u) {
//		IMatrix l = new IMatrix(3,3);
//        l.setIdentity();
//        return l;
//	}

//	public IMatrix modifyInternalVariableOperator(IMatrix e, IMatrix p) {
//		// TODO Auto-generated method stub
//		return null;
//	}
//
//	public int getDominion() {
//		return 2;
//	}
//
//	public double getIntegrationFactor(IVector n, IMatrix cN, GeometricProperties gps) {
//    	return gps.getThickness();
//	}
//
//	public ArrayList getDOFLabels(int n) {
//		// TODO Auto-generated method stub
//		return null;
//	}   
    
	/** Return the jacobian matrix.
	*@param dl The matrix of local derivates.
	*@param cN The matrix of nodal coordinates.
	*@return dl * cN The jacobian matrix.
	*/
//	private IMatrix getJacobian(IMatrix dl, IMatrix cN)
//	{
//		IMatrix jacobian = new IMatrix(this.getDominion(),this.getDominion());
//		jacobian.setZero();
//		jacobian.mul(dl, cN);
//		return(jacobian);
//	}
//	
//	/** Return the inverse of jacobian matrix.
//	    *@param a The jacobian matrix.
//	    *@return the inverse of jacobian matrix.
//	    */
//	    private IMatrix invertJacobian(IMatrix a)
//	    {
//	        IMatrix b = new IMatrix(2,2);
//	        b.setZero();
//	        b.setElement(0,0,a.getElement(1,1));
//	        b.setElement(0,1,((-1)*(a.getElement(1,0))));
//	        b.setElement(1,0,((-1)*(a.getElement(0,1))));
//	        b.setElement(1,1,a.getElement(0,0));
//	        b.transpose();
//	        b.setScale(1/a.determinantLU());
//	        return (b);
//	    }
	    
}